Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHubBranches: Add New/Remove-GitHubRepositoryBranch Functions #200

Closed
wants to merge 18 commits into from
Closed

GitHubBranches: Add New/Remove-GitHubRepositoryBranch Functions #200

wants to merge 18 commits into from

Conversation

X-Guardian
Copy link
Contributor

@X-Guardian X-Guardian commented May 29, 2020

This PR is superseded by PR #256

Description

This PR adds the following functions to the GitHubBranches module:

  • New-GitHubRepositoryBranch
  • Remove-GitHubRepositoryBranch

Issues Fixed

None

References

GitHub Repos API

Checklist

  • You actually ran the code that you just wrote, especially if you did just "one last quick change".
  • Comment-based help added/updated, including examples.
  • Static analysis is reporting back clean.
  • New/changed code adheres to our coding guidelines.
  • Changes to the manifest file follow the manifest guidance.
  • Unit tests were added/updated and are all passing. See testing guidelines.
  • Relevant usage examples have been added/updated in USAGE.md.
  • If desired, ensure your name is added to our Contributors list

Copy link
Member

@HowardWolosky HowardWolosky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there's some strong overlap between this and @raghav710's #97. I think that needs to be resolved first. Let me check on #97 in it's thread.

GitHubBranches.ps1 Show resolved Hide resolved
@HowardWolosky HowardWolosky added enhancement An issue or pull request introducing new functionality to the project. api-refs Work to complete the API's defined here: https://developer.github.com/v3/git/refs/ labels Jun 2, 2020
@X-Guardian
Copy link
Contributor Author

Can we trigger the CI for this PR?

@HowardWolosky
Copy link
Member

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@X-Guardian
Copy link
Contributor Author

The Context When the origin branch cannot be found tests are failing because I'm getting very different error objects back between PowerShell 5 and 7 when calling Get-GitHubRepositoryBranch with a branch name that doesn't exist.
Looking at Invoke-GHRestMethod in GithubCore, for this scenario using PowerShell 5, the [System.Net.WebException] code block at line 416 is being run, but with PowerShell 7, for the same error we are falling through to the final else block at line 459.

Adding some debug code, I can see that in PowerShell 5, $_.Exception.PSTypeNames at line 416 is:

System.Net.WebException
System.InvalidOperationException
System.SystemException
System.Exception
System.Object

and in PowerShell 7 $_.Exception.PSTypeNames at line 416 is:

Microsoft.PowerShell.Commands.HttpResponseException
System.Net.Http.HttpRequestException
System.Exception
System.Object

Adding -or $_.Exception -is [Microsoft.PowerShell.Commands.HttpResponseException]) to line 416 to make PowerShell 7 take the same code path as PowerShell 5, then causes PowerShell 7 to raise the following exception:

Get-HttpWebResponseContent: \\nas01\data\Users\Simon\Documents\GitHub\X-Guardian\PowerShellForGitHub\GitHubCore.ps1:429
Line |
 429 |  …    $rawContent = Get-HttpWebResponseContent -WebResponse $ex.Response
     |                                                             ~~~~~~~~~~~~
     | Cannot process argument transformation on parameter 'WebResponse'. Cannot convert the "StatusCode:
     | 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent,
     | Headers: {   Date: Fri, 05 Jun 2020 22:17:24 GMT   Server: GitHub.com   Status: 404 Not Found
     | X-RateLimit-Limit: 5000   X-RateLimit-Remaining: 4981   X-RateLimit-Reset: 1591395451
     | X-OAuth-Scopes: admin:org, delete_repo, repo   X-Accepted-OAuth-Scopes: repo   X-GitHub-Media-Type:
     | github.nebula-preview; format=json, github.baptiste-preview; format=json, github.mercy-preview;
     | format=json   Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP,
     | X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes,
     | X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset   Access-Control-Allow-Origin: *
     | Strict-Transport-Security: max-age=31536000; includeSubdomains; preload   X-Frame-Options: deny
     | X-Content-Type-Options: nosniff   X-XSS-Protection: 1; mode=block   Referrer-Policy:
     | origin-when-cross-origin, strict-origin-when-cross-origin   Content-Security-Policy: default-src
     | 'none'   Vary: Accept-Encoding   Vary: Accept   Vary: X-Requested-With   X-GitHub-Request-Id:
     | E2FD:32667:1C74CFD:222AAEC:5EDAC474   Content-Type: application/json; charset=utf-8   Content-Length:
     | 88 }" value of type "System.Net.Http.HttpResponseMessage" to type "System.Net.HttpWebResponse".

I think Invoke-GHRestMethod and maybe other core functions needs some refactoring to generate consistent error exceptions for PowerShell 5 and 7.

@HowardWolosky
Copy link
Member

I've opened #223 to track that problem.

@X-Guardian
Copy link
Contributor Author

Can we trigger the CI for this PR?

@X-Guardian
Copy link
Contributor Author

X-Guardian commented Jun 7, 2020

I've added the -Force switch to the Remove-GitHubRepositoryBranch function as detailed in issue #218.

@X-Guardian
Copy link
Contributor Author

I've added temporary code to the New-GitHubRepositoryBranch function to work around the differences between the current PS5 and PS7 exception object as tracked in issue #223.

@X-Guardian
Copy link
Contributor Author

Can we trigger the CI for this PR?

@HowardWolosky
Copy link
Member

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@X-Guardian X-Guardian marked this pull request as ready for review June 12, 2020 18:28
@X-Guardian
Copy link
Contributor Author

Great to have a fast CI now! This PR is ready for final review.

@HowardWolosky
Copy link
Member

Great to have a fast CI now!

Thanks for the encouragement/push to do the extra work to make the additional accounts to allow for the parallel processing!

This PR is ready for final review.

Will get to the review this weekend or early next week. Thanks again for all your work here!

@X-Guardian
Copy link
Contributor Author

Hi @HowardWolosky, I've added pipeline support to these new functions. Can we trigger the CI for this PR?

@HowardWolosky
Copy link
Member

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky HowardWolosky added api completeness This is basic API functionality that hasn't been implemented yet. and removed enhancement An issue or pull request introducing new functionality to the project. labels Jun 18, 2020
@X-Guardian
Copy link
Contributor Author

Can we trigger the CI for this PR?

Copy link
Member

@HowardWolosky HowardWolosky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally had time to review this one in context to #97.

I think both PR's have a place in the module, but it would make sense for these two functions to be built on-top of New-GitHubReference/Remove-GitHubReference once that goes in.

GitHubBranches.ps1 Outdated Show resolved Hide resolved
GitHubBranches.ps1 Outdated Show resolved Hide resolved
GitHubBranches.ps1 Outdated Show resolved Hide resolved
GitHubBranches.ps1 Show resolved Hide resolved
GitHubBranches.ps1 Show resolved Hide resolved
GitHubBranches.ps1 Outdated Show resolved Hide resolved
GitHubBranches.ps1 Outdated Show resolved Hide resolved
GitHubBranches.ps1 Outdated Show resolved Hide resolved
GitHubBranches.ps1 Outdated Show resolved Hide resolved
sha = $originBranch.commit.sha
}

$params = @{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it probably makes more sense to allow #97 to go in, and then have this function be a wrapper on top of New-GitHubReference. You can still make this an intelligent helper that can automate retrieving the sha via an internal call to Get-GitHubRepositoryBranch when it hasn't been passed in manually or via the pipeline, but given that we'll want New-GitHubReference in the module anyway to be able to support tag references, it seems like it makes more sense to not duplicate the logic of forming a call to create new references across two functions. Same for Remove-*.

@X-Guardian
Copy link
Contributor Author

This PR is superseded by PR #256

@X-Guardian X-Guardian closed this Jun 29, 2020
@HowardWolosky HowardWolosky added the superseded The PR was replaced by a newer PR label Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api completeness This is basic API functionality that hasn't been implemented yet. api-refs Work to complete the API's defined here: https://developer.github.com/v3/git/refs/ superseded The PR was replaced by a newer PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants